<template>
  <div class="main">

    <div class="question_container">
      <div class="question" v-for="(item,index) in questionList" :key="item.id">
        <questionSelect :question="item" :index="index" @selected="handleSelected" @unselected="handleUnselected"></questionSelect>
      </div>
    </div>
  </div>
</template>

<script>
import axiosinstance from '@/util/http'
import QuestionSelect from '@/components/Question/QuestionSelect'


export default {
  name: "PaperAddQuestion",
  computed: {},
  data() {
    return{
      page: 1,
      pageSize: 10,
      qb_id:13,
      questionList:[],
      //需要添加题目的ID数组
      questionArray:[],
    }
  },
  methods: {
    getQuestionBases() {

    },
    getQuestionList(qb_id) {
      axiosinstance.get('/questionbase/questionlist', {
        params: {
          page: this.page,
          pagesize: this.pageSize,
          username: this.$store.getters.getuser.username,
          qb_id: qb_id,
        }
      }).then(res =>{
        console.log(res)
        this.questionList = res.data.data;
      })
    },
    handleSelected(e){
      this.questionArray.push(e.id);
      this.questionArray.sort((a,b)=>a-b);
      console.log("目前选择的题目列表" + this.questionArray)
    },
    handleUnselected(e){
      let index = this.questionArray.indexOf(e.id);
      this.questionArray.splice(index,1);
      console.log("目前选择的题目列表" + this.questionArray)
    },



  },
  created() {
    this.getQuestionList(this.qb_id);
  },
  components:{
    questionSelect:QuestionSelect
  }

}
</script>

<style scoped lang="less">
* {
  padding: 0;
  margin: 0;
}

.container {

}
</style>